<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8" />
  <title>用户管理</title>
  <link href="https://cdn.staticfile.org/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container mt-5">
  <h2>用户列表</h2>
  <a href="/admin/users/user_add" class="btn btn-primary mb-3">添加用户</a>
  <table class="table table-bordered">
    <thead>
    <tr>
      <th>ID</th>
      <th>用户名</th>
      <th>角色</th>
      <th>创建时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="user : ${users}">
      <td th:text="${user.id}"></td>
      <td th:text="${user.username}"></td>
      <td th:text="${user.role}"></td>
      <td th:text="${#dates.format(user.createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
      <td>
        <a th:href="@{'/admin/users/edit/' + ${user.id}}" class="btn btn-sm btn-warning">编辑</a>

        <!-- 判断是否是当前登录用户，是则禁用删除按钮 -->
        <span th:if="${user.username == currentUsername}">
          <button type="button" class="btn btn-sm btn-danger" disabled title="不能删除自己">删除</button>
        </span>
        <a th:if="${user.username != currentUsername}"
           th:href="@{'/admin/users/delete/' + ${user.id}}"
           class="btn btn-sm btn-danger"
           onclick="return confirm('确定删除该用户？')">删除</a>
      </td>
    </tr>
    </tbody>
  </table>
  <a href="/" class="btn btn-secondary">返回首页</a>
</div>
</body>
</html>
